/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor
 */
package demo.axitdn.physic;

import android.util.Log;

/**
 * 
 * @author VAIO
 */
public class CircularMotion implements Force {
	Vector3f ro;
	Vector3f rr;
	Vector3f omega;
	Vector3f v0;
	Vector3f a0;
	Vector3f a;
	Vector3f ur;
	Vector3f oxy;
	float R = 5;
	float w = (float) (Math.PI / 2f);
	Vector3f rt;
	Vector3f rtt;
	private boolean sign;
	Vector3f tm;
	public CircularMotion(Vector3f p, Vector3f vo, Vector3f o, float r,float angle, double t) {
		v0 = vo;
		oxy = o;
		R = r;
		double cta = Math.atan2(v0.y, v0.x);
		rt=new Vector3f();		
		rt.x = (float) (R * Math.cos(cta + Math.PI / 2));
		rt.y = (float) (R * Math.sin(cta + Math.PI / 2));	
		
		w = v0.length() / R;
		omega = new Vector3f(0, 0, w);
		tm=rt.cross(v0);
		
//		ro=rt.negate().addLocal(o);
//		Vector3f tt=o.subtract(ro);
//		p=p.addLocal(tt);
	}

	public Vector3f getR() {
		return rt;
	}

	public Vector3f getA() {
		return a;
	}
	
	public Vector3f getT() {
		return tm;
	}

	public Vector3f getCenter() {
		return ro;
	}

	public void increase(double t, float d, float util) {

	}

	public void decrease(double t, float d, float util) {
		
	}
	Vector3f at=new Vector3f();
	@Override
	public Vector3f ff(State state, double t) {
		// TODO Auto-generated method stub		
		double cta = Math.atan2(state.velocity.y, state.velocity.x);
		rt.x = (float) (R * Math.cos(cta + Math.PI / 2));
		rt.y = (float) (R * Math.sin(cta + Math.PI / 2));		
		//tm=rt.cross(state.velocity);
		at=state.velocity.normalize().mult(0.1f).negate();
		//a = omega.cross(omega.cross(rt));
		float vv=state.velocity.length();
		a=rt.normalize().negate().mult((vv*vv/R));
		return a;
	}

	@Override
	public void update(State state) {
		// TODO Auto-generated method stub
		state.velocity=state.velocity.add(at);		
		
	}
	
	
}